```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>单例模式解析 | 设计模式精要</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f9f9f9;
            color: #333;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-left: 4px solid #667eea;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .feature-icon {
            color: #667eea;
            font-size: 2rem;
            margin-bottom: 1rem;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 5rem;
            line-height: 0.65;
            margin: 0.1em 0.2em 0 0;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-6xl font-bold mb-6 font-serif">单例模式</h1>
            <p class="text-xl md:text-2xl mb-8 max-w-3xl mx-auto leading-relaxed">
                确保一个类只有一个实例，并提供全局访问点的创建型设计模式
            </p>
            <div class="flex justify-center space-x-4">
                <div class="px-6 py-3 bg-white text-indigo-600 rounded-full font-medium hover:bg-gray-100 transition duration-300">
                    <i class="fas fa-book-open mr-2"></i>深入了解
                </div>
                <div class="px-6 py-3 border border-white text-white rounded-full font-medium hover:bg-white hover:text-indigo-600 transition duration-300">
                    <i class="fas fa-code mr-2"></i>代码示例
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <p class="text-lg leading-relaxed mb-8 drop-cap">
                单例模式（Singleton Pattern）是一种创建型设计模式，旨在确保一个类只有一个实例，并提供一个全局访问点来获取这个唯一的实例。它适用于需要控制对象创建次数的场景，以节省资源并避免冗余。
            </p>
            <div class="grid md:grid-cols-3 gap-8">
                <div class="card bg-white p-8 rounded-lg shadow-md">
                    <div class="feature-icon">
                        <i class="fas fa-university"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4 font-serif">唯一性</h3>
                    <p class="text-gray-600">类只能有一个实例，确保全局一致性</p>
                </div>
                <div class="card bg-white p-8 rounded-lg shadow-md">
                    <div class="feature-icon">
                        <i class="fas fa-globe"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4 font-serif">全局访问</h3>
                    <p class="text-gray-600">提供全局访问点获取唯一实例</p>
                </div>
                <div class="card bg-white p-8 rounded-lg shadow-md">
                    <div class="feature-icon">
                        <i class="fas fa-clock"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-4 font-serif">延迟加载</h3>
                    <p class="text-gray-600">在第一次使用时才创建实例</p>
                </div>
            </div>
        </section>

        <!-- Implementation -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 font-serif border-b-2 border-indigo-100 pb-4">实现方式</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-2xl font-bold mb-4 font-serif text-indigo-600">饿汉式</h3>
                    <p class="mb-4 text-gray-700">这种方法在类加载时就创建实例，不管是否使用它。</p>
                    <div class="code-block rounded-lg p-4 overflow-x-auto">
                        <pre class="text-sm"><code>public class Singleton {
    // 1. 创建一个静态的唯一实例
    private static final Singleton INSTANCE = new Singleton();

    // 2. 私有化构造函数，防止外部实例化
    private Singleton() {}

    // 3. 提供一个公共的静态方法来获取唯一实例
    public static Singleton getInstance() {
        return INSTANCE;
    }
}</code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-4 font-serif text-indigo-600">懒汉式</h3>
                    <p class="mb-4 text-gray-700">这种方法在第一次使用时才创建实例，但需要考虑线程安全问题。</p>
                    <div class="code-block rounded-lg p-4 overflow-x-auto">
                        <pre class="text-sm"><code>public class Singleton {
    // 1. 延迟加载实例，使用 volatile 关键字保证线程安全
    private static volatile Singleton instance;

    // 2. 私有化构造函数，防止外部实例化
    private Singleton() {}

    // 3. 提供一个公共的静态方法来获取唯一实例
    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Use Cases -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 font-serif border-b-2 border-indigo-100 pb-4">使用场景</h2>
            
            <div class="space-y-12">
                <div class="card bg-white p-8 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 font-serif text-indigo-600">1. 配置管理</h3>
                    <p class="mb-6 text-gray-700">例如，数据库连接池通常采用单例模式来确保全局只有一个连接池实例，避免重复创建连接池浪费资源。</p>
                    <div class="code-block rounded-lg p-4 overflow-x-auto">
                        <pre class="text-sm"><code>public class DatabaseConnectionPool {
    private static volatile DatabaseConnectionPool instance;

    private DatabaseConnectionPool() {
        // 初始化连接池
    }

    public static DatabaseConnectionPool getInstance() {
        if (instance == null) {
            synchronized (DatabaseConnectionPool.class) {
                if (instance == null) {
                    instance = new DatabaseConnectionPool();
                }
            }
        }
        return instance;
    }

    // 连接池相关的方法
}</code></pre>
                    </div>
                </div>
                
                <div class="card bg-white p-8 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 font-serif text-indigo-600">2. 日志管理</h3>
                    <p class="mb-6 text-gray-700">日志记录器通常也是单例的，因为所有的日志信息需要集中记录，并且多个对象共享同一个日志实例，避免多个日志实例写入同一文件导致的竞争问题。</p>
                    <div class="code-block rounded-lg p-4 overflow-x-auto">
                        <pre class="text-sm"><code>public class Logger {
    private static volatile Logger instance;

    private Logger() {
        // 初始化日志系统
    }

    public static Logger getInstance() {
        if (instance == null) {
            synchronized (Logger.class) {
                if (instance == null) {
                    instance = new Logger();
                }
            }
        }
        return instance;
    }

    public void log(String message) {
        // 写日志的代码
    }
}</code></pre>
                    </div>
                </div>
                
                <div class="card bg-white p-8 rounded-lg shadow-md">
                    <h3 class="text-2xl font-bold mb-4 font-serif text-indigo-600">3. 配置文件读取</h3>
                    <p class="mb-6 text-gray-700">有时我们需要一个类来读取配置文件，这个类应该是单例的，以确保配置文件读取的统一性和一致性。</p>
                    <div class="code-block rounded-lg p-4 overflow-x-auto">
                        <pre class="text-sm"><code>public class ConfigurationManager {
    private static volatile ConfigurationManager instance;

    private Properties properties;

    private ConfigurationManager() {
        // 读取配置文件
        properties = new Properties();
        // 加载配置
    }

    public static ConfigurationManager getInstance() {
        if (instance == null) {
            synchronized (ConfigurationManager.class) {
                if (instance == null) {
                    instance = new ConfigurationManager();
                }
            }
        }
        return instance;
    }

    public String getProperty(String key) {
        return properties.getProperty(key);
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 font-serif border-b-2 border-indigo-100 pb-4">单例模式结构</h2>
            <div class="bg-white p-8 rounded-lg shadow-md">
                <div class="mermaid">
                    graph TD
                        A[Client] -->|调用| B[Singleton.getInstance()]
                        B --> C{实例是否存在?}
                        C -->|否| D[创建新实例]
                        C -->|是| E[返回现有实例]
                        D --> E
                        E --> F[返回实例给Client]
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">探索编程世界的奥秘</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-300">
                        <i class="fas fa-external-link-alt mr-2"></i>访问技术小馆
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```